﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Solidorbrazedturningtoolpointedstraightdesign
    {
        public static void _Solidorbrazedturningtoolpointedstraightdesign(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数


            double h = 8.07;
            double hf = 6.07;
            double b = 8.04;
            double lh = 11.6;
            double lpr = 25.25;
            double oal = 42.81;
            double kapr = 55;
            double s = 1;
            double l = 3.36;



            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal, v1.Y - h + hf);
            Vector2 v3 = new Vector2(v2.X, v2.Y - s);
            Vector2 v4 = new Vector2(v3.X - l / 19.765, v3.Y);
            Vector2 v5 = new Vector2(v4.X - lh / 8.227, v1.Y - h);
            Vector2 v6 = new Vector2(v1.X, v5.Y);
            Vector2 v9 = new Vector2(v2.X - lh / 1.217, v2.Y);
            Vector2 v10 = new Vector2(v2.X - lh, v1.Y);

            Vector2 v13 = new Vector2(v6.X, v6.Y - oal / 1.415);
            Vector2 v14 = new Vector2(v13.X, v13.Y - b);
            Vector2 v15 = new Vector2(v2.X, v13.Y - b / 2);
            Vector2 v16 = new Vector2(v15.X - (b / 2) * Math.Tan(kapr * pi / 180), v13.Y);
            Vector2 v17 = new Vector2(v16.X, v14.Y);
            Vector2 v18 = new Vector2(v9.X, v13.Y);
            Vector2 v19 = new Vector2(v18.X, v14.Y);
            Vector2 v20 = fun.Polar(v15, (kapr + 90) * pi / 180, l);
            Vector2 v21 = new Vector2(v18.X, v20.Y);
            Vector2 v22 = fun.Polar(v15, (-kapr - 90) * pi / 180, l);
            Vector2 v23 = new Vector2(v19.X, v22.Y);
            Vector2 v24 = new Vector2(v10.X, v13.Y);
            Vector2 v25 = new Vector2(v24.X, v14.Y);

            Vector2 v7 = new Vector2(v20.X, v2.Y);
            Vector2 v8 = new Vector2(v7.X, v3.Y);
            Vector2 v11 = new Vector2(v16.X, v2.Y);
            Vector2 v12 = new Vector2(v11.X, v5.Y);
            Vector2 v26 = new Vector2(v2.X - lpr, v1.Y);
        
            Vector2 v28 = new Vector2(v26.X, v13.Y - b / 2);
            



            //作图
            LwPolyline line1 = new LwPolyline();
            line1.Vertexes.Add(new LwPolylineVertex(v4));
            line1.Vertexes.Add(new LwPolylineVertex(v5));
            line1.Vertexes.Add(new LwPolylineVertex(v6));
            line1.Vertexes.Add(new LwPolylineVertex(v1));
            line1.Vertexes.Add(new LwPolylineVertex(v10));
            line1.Vertexes.Add(new LwPolylineVertex(v9));
            line1.Vertexes.Add(new LwPolylineVertex(v2));
            line1.Vertexes.Add(new LwPolylineVertex(v3));
            line1.Vertexes.Add(new LwPolylineVertex(v8));
            line1.Vertexes.Add(new LwPolylineVertex(v7));
            line1.Vertexes.Add(new LwPolylineVertex(v11));
            line1.Vertexes.Add(new LwPolylineVertex(v12));
            fun.PolyFill(dxf, line1, 0.2, contour);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v18));
            line2.Vertexes.Add(new LwPolylineVertex(v19));
            line2.Vertexes.Add(new LwPolylineVertex(v25));
            line2.Vertexes.Add(new LwPolylineVertex(v24));
            line2.Vertexes.Add(new LwPolylineVertex(v16));
            line2.Vertexes.Add(new LwPolylineVertex(v15));
            line2.Vertexes.Add(new LwPolylineVertex(v17));
            line2.Vertexes.Add(new LwPolylineVertex(v14));
            line2.Vertexes.Add(new LwPolylineVertex(v13));
            line2.Vertexes.Add(new LwPolylineVertex(v16));
            fun.PolyFill(dxf, line2, 0.2, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v20));
            line3.Vertexes.Add(new LwPolylineVertex(v21));
            line3.Vertexes.Add(new LwPolylineVertex(v23));
            line3.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, line3, 0.2, contour);

            fun.drawcircle(dxf, v2, 1, 0.02, dimensioning);

            fun.drawcircle(dxf, v15, 1, 0.02, dimensioning);


            //坐标系
            fun.Axis(dxf, v6, 90, 180, "Y", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v26, 90, 180, "Y", "Z", "MCS", 0.5, 2, 0);

            fun.Axis(dxf, v13, -90, 180, "X", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v28, -90, 180, "X", "Z", "MCS", 0.5, 2, 0);


            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;



            fun.dimrot1(dxf, v1, v6, 90, h, 1, height, arrowsize, exline, "H", "", "");

            fun.dimrot1(dxf, v2, v5, -90, h, 1, height, arrowsize, exline, "HF", "", "");

            fun.dimrot1(dxf, v2, v10, -90, h + (v2.X + v5.X) / 2 - (v10.X + v2.X) / 2, 1, height, arrowsize, exline, "HTA", "", "");

            //2
            fun.dimrot1(dxf, v13, v14, 90, h, 1, height, arrowsize, exline, "B", "", "");

            fun.dimrot1(dxf, v25, v28, 90, h * 1.5, 1, height, arrowsize, exline, "=", "", "");

            fun.dimrot1(dxf, v24, v28, 90, h * 1.5, 1, height, arrowsize, exline, "=", "", "");

            fun.dimrot1(dxf, v16, v15, -90, h + (v2.X + v5.X) / 2 - (v15.X + v16.X) / 2, 1, height, arrowsize, exline, "WF,WTA", "", "");

            fun.dimrot1(dxf, v15, v24, 0, h * 1.5, 1, height, arrowsize, exline, "LH", "", "");

            fun.dimrot1(dxf, v15, v28, 0, h * 2.5, 1, height, arrowsize, exline, "LPR,LTA", "", "");

            fun.dimrot1(dxf, v14, v15, 180, h * 1.5, 1, height, arrowsize, exline, "OAL,LF", "", "");

            fun.jdbz2(dxf, new Line(v15, fun.Polar(v15, 90 * pi / 180, 0.1)), new Line(v15, fun.Polar(v15, (90 + kapr) * pi / 180, 0.1)), h, height, arrowsize, exline, "KAPR", "", "");

            fun.jdbz2(dxf, new Line(v15, fun.Polar(v15, (-kapr - 90) * pi / 180, 0.1)), new Line(v15, fun.Polar(v15, -90 * pi / 180, 0.1)), h, height, arrowsize, exline, "KAPR", "", "");

            fun.jt(dxf, new Vector2(v15.X + oal / 7.686, v15.Y - b / 0.881), -90, 5, height, "FDP");

            fun.jt(dxf, new Vector2(v13.X + oal / 3.5675, v13.Y), 115, 5, height, "CCMS");

            fun.text1(dxf, new Vector2(v2.X, v2.Y + h / 6.256), 90, "CRP");

            fun.text1(dxf, new Vector2(v15.X + lh / 13.333, v15.Y - b / 2.056), 90, "CRP");




            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

}
}